package com.example.wxy.bbtapp.Common;

import android.util.Log;
import android.widget.Toast;

import com.example.wxy.bbtapp.Service.BindService;
import com.example.wxy.bbtapp.Startup.AppSettings;
import com.example.wxy.bbtapp.myApplication;

import org.xutils.common.Callback;

/**
 * Created by wxy on 2017/9/6.
 */

public class httpCallBack<T>  implements Callback.CommonCallback<T>{

    private String Title ="";

    private int getTokenCount=0;

    public httpCallBack(String title)
    {
        this.Title = title;
    }


    @Override
    public void onSuccess(T result) {

    }

    @Override
    public void onError(Throwable ex, boolean isOnCallback) {
        if(Title != "")
        Toast.makeText(myApplication.getContext(), "服务器小哥哥好像不给我 " + Title + " 哦",Toast.LENGTH_LONG).show();
        Log.d(AppSettings.DebugTag, Title + "CallBack Error:" +  ex.getMessage());

        // 如果没有认证就再请求一次认证，为了避免死循环做了个title判断
        if(ex!=null && ex.getMessage() != null && ex.getMessage().equals("Unauthorized") && Title != "getTokenTwo")
        {
            Log.d(AppSettings.DebugTag, " request Token again ");
            BindService.getCook(null);
        }

    }

    @Override
    public void onCancelled(CancelledException cex) {
        Log.d(AppSettings.DebugTag, "CallBack onCancelled:" +  cex.getMessage());
    }

    @Override
    public void onFinished() {

    }
}
